﻿<UserControl x:Class="Adalbertus.BudgetPlanner.Views.BudgetPlanning.BudgetPlanView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:cal="http://www.caliburnproject.org" 
             xmlns:view="clr-namespace:Adalbertus.BudgetPlanner.Views.BudgetPlanning"
             xmlns:ext="clr-namespace:Adalbertus.BudgetPlanner.Views.Extensions"
>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Budget header -->
        <GroupBox Grid.Row="0" Header="Budżet">
            <StackPanel>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <WrapPanel Grid.Column="0" VerticalAlignment="Center">
                        <Label>Od</Label>
                        <DatePicker SelectedDate="{Binding DateFrom}" SelectedDateFormat="Long" />
                    </WrapPanel>
                    <WrapPanel Grid.Column="1">
                        <Label>Do</Label>
                        <DatePicker SelectedDate="{Binding DateTo}" SelectedDateFormat="Long" />
                    </WrapPanel>
                </Grid>
                <view:RevenuesView DataContext="{Binding RevenuesViewModel}" />
            </StackPanel>
        </GroupBox>

        <!-- Budget details -->
        <Grid Grid.Row="1" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.3*" MinWidth="300" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="0.7*" MinWidth="450"/>
            </Grid.ColumnDefinitions>

            <!-- Budget plans -->
            <GroupBox Grid.Column="0" Header="Plan budżetowy">
                <DataGrid ItemsSource="{Binding BudgetPlanList}" SelectionMode="Single"
                          SelectedItem="{Binding SelectedBudgetPlan}" AutoGenerateColumns="False"
                          >
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding Name}" Header="Nazwa"/>
                        <DataGridTextColumn Binding="{Binding TotalValue}" Header="Łączna wartość"/>
                    </DataGrid.Columns>
                    <DataGrid.RowDetailsTemplate>
                        <DataTemplate>
                            <Border BorderBrush="AliceBlue" BorderThickness="1" CornerRadius="4" Margin="10" Padding="10" Background="Beige">
                                <StackPanel>
                                    <WrapPanel>
                                        <Label>Wartość:</Label>
                                        <TextBox Text="{Binding NewDetailValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                                                 Width="30"
                                                 ext:FocusExtension.IsFocused="{Binding IsNewDetailValueFocused}"/>
                                        <Label>Opis:</Label>
                                        <TextBox Width="30" Text="{Binding NewDetailDescription, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
                                        <Button Content="Dodaj" cal:Message.Attach="[Event Click] = [Action AddPlanDetailItem()]" />
                                    </WrapPanel>
                                    <DataGrid ItemsSource="{Binding Details}" AutoGenerateColumns="False"
                                              CanUserAddRows="True" CanUserDeleteRows="True">
                                        <DataGrid.Columns>
                                            <DataGridTextColumn Header="Wartość" Binding="{Binding Value}" />
                                            <DataGridTextColumn Binding="{Binding Description}" Header="Opis"/>
                                        </DataGrid.Columns>
                                    </DataGrid>
                                </StackPanel>
                            </Border>
                        </DataTemplate>
                    </DataGrid.RowDetailsTemplate>
                </DataGrid>
            </GroupBox>

            <GridSplitter Grid.Column="1" Width="2"
                          HorizontalAlignment="Right" VerticalAlignment="Stretch" 
                          ResizeBehavior="PreviousAndNext" Background="LightSteelBlue"/>

            <!-- Budget expenses -->
            <GroupBox Grid.Column="2" Header="Realizacja budżetu">
                <StackPanel>
                    <view:ExpensesView DataContext="{Binding ExpensesViewModel}" />
                </StackPanel>
            </GroupBox>
        </Grid>

        <StackPanel Grid.Row="2" HorizontalAlignment="Right">
            <Button Content="Zatwierdź" cal:Message.Attach="[Event Click] = [Action CreateBudget()]"/>
        </StackPanel>
    </Grid>
</UserControl>
